// import { ListPage } from './../../list/list';
import { Component, Injector } from "@angular/core";
import { IonicPage, NavController, NavParams } from "ionic-angular";
import { UserService } from "./../../../providers/UserService";
import { StorageService } from "./../../../providers/StorageService";
import { BasePage } from "../../basePage";

/**
 * Generated class for the TxsettingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: "page-txsetting",
  templateUrl: "txsetting.html"
})
export class TxsettingPage extends BasePage {
  setting = {};
  /**获取到用户的个人信息 */
  userinfo: any;

  /**有店铺邀请我加入 */

  InviteMe: boolean;

  /**有店铺同意我的入店申请 */

  InviteTo: boolean;

  /**有人购买店铺服务 */

  shopService: boolean;
  settingAPI = {};
  /*保存是否设置了声音的设置 true 代表有声音提示*/

  gandalf: boolean;
  /*保存是否设置了 震动的设置  true 代表了有震动的提示*/
  isShake: boolean;
  
  /**按钮开关储存 0或''为flase  1为true*/
  Bool = {
    gandalf: "",
    isShake: "",
    InviteMe: "",
    InviteTo: "",
    shopService: ""
  };

  constructor(
    injector: Injector,
    public userService: UserService,
    public stc: StorageService
  ) {
    super(injector);
    this.userinfo = this.stc.read("userinfo");
  }

  ionViewDidLoad() {
    console.log("ionViewDidLoad TxsettingPage");
    var leng = localStorage.getItem('bool');
    let arry=  JSON.parse(leng);
    console.log(localStorage)
    if(localStorage.getItem('InviteMe')==''||localStorage.getItem('InviteMe')=='0'){
      this.InviteMe=false
    }else{
      this.InviteMe=true
    }
    if(localStorage.getItem('InviteTo')==''||localStorage.getItem('InviteTo')=='0'){
      this.InviteTo=false
    }else{
      this.InviteTo=true
    }
    if(localStorage.getItem('gandalf')==''||localStorage.getItem('gandalf')=='0'){
      this.gandalf=false
    }else{
      this.gandalf=true
    }
    if(localStorage.getItem('isShake')==''||localStorage.getItem('isShake')=='0'){
      this.isShake=false
    }else{
      this.isShake=true
    }
    if(localStorage.getItem('shopService')==''||localStorage.getItem('shopService')=='0'){
      this.shopService=false
    }else{
      this.shopService=true
    }
  }

  async getSettingAPI() {
    let param = { user_id: this.userinfo["user_id"] };
    let result = await this.userService.getSettingAPI(param);
    console.log(result);
  }
  // Golist(){
  //   this.navCtrl.push(ListPage)
  // }

  /**按钮开关储存 0或''为flase  1为true*/
/**声音 */
  toChangeVoice() {
    if (this.gandalf) {
      let gandalf='1'
      localStorage.setItem("bool", JSON.stringify(this.Bool));
    } else {
      let gandalf= "0";
      localStorage.setItem("bool", JSON.stringify(this.Bool));
    }
  }
  /**震动*/
  toChangeShake() {
    if (this.isShake) {
      let isShake = "1";

      localStorage.setItem("isShake", isShake);
    } else {
      let isShake = "0";
      localStorage.setItem("isShake",isShake);

    }
  }
  /**有店铺邀请我加入*/
  toChangeInviteMe() {
    if (this.InviteMe) {
      let InviteMe = "1";
      localStorage.setItem("InviteMe",InviteMe);

    } else {
      let InviteMe = "0";
      localStorage.setItem("InviteMe",InviteMe);
     
    }
  }
  /**有店铺同意我的入店申请*/
  toChangeInviteTo() {
    if (this.InviteTo) {
      let InviteTo = "1";
      localStorage.setItem("InviteTo",InviteTo);
 console.log(localStorage)
    } else {
      let InviteTo = "0";
      localStorage.setItem("InviteTo",InviteTo);
      console.log(localStorage)
    }
  }
  /**有人购买店铺服务*/
  toChangeService() {
    if (this.shopService) {
      let shopService = "1";
      localStorage.setItem("shopService",shopService);
      console.log(localStorage)

    } else {
      let shopService = "0";
      localStorage.setItem("shopService",shopService);
      console.log(localStorage)
    }
  }
  dismissCLI() {
    this.navCtrl.pop();
  }
}
